package com.cgy.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cgy.entity.Keshi;
import com.cgy.service.keshiService;

import util.LayuiJsonUtils;

@RestController
@RequestMapping("keshi")
@CrossOrigin
public class keshiController {
	@Autowired
	private keshiService keshiservice;
	/**
	 * 动态查询所有科室
	 */
	@GetMapping
	public LayuiJsonUtils<Keshi> findAllBynameKeshi(LayuiJsonUtils<Keshi> lj,Keshi k){
		Pageable pageable = PageRequest.of(lj.getPage(), lj.getLimit());
		Page<Keshi> keshi  = keshiservice.findBynameKeshi(k, pageable);
		lj.setData(keshi.getContent());
		lj.setCount(keshi.getTotalElements());
		return lj;
	}
	@RequestMapping("findAllKeshi")
	public List<Keshi> findAll(){
		return keshiservice.findAll();
	}
	@PostMapping
	//添加科室
	public Keshi addKeshi(Keshi k) {
		return keshiservice.addAndUpdateKeshi(k);
	}
	//修改科室信息
	@PutMapping
	public Keshi updatekeshi(Keshi k) {
		return keshiservice.addAndUpdateKeshi(k);
	}
	//删除科室
	@DeleteMapping("{kid}")
	public Integer deleteKeshi(@PathVariable("kid") Integer kid) {
		return  keshiservice.deleteKeshi(kid);
	}
}
